package com.gjy.nwpufindseats.Fragment;

import java.util.ArrayList;
import com.gjy.nwpufindseats.baseData.Global;
import com.gjy.nwpufindseats.R;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.TextView;

public class Fragment_room_info extends Fragment {
	public final Integer COLUMN=6;//列号
	
	TableLayout occupiedRoomTable;
	Bundle bundle;
	View ocRoomInfo;
	TextView textView;
	public static ArrayList<String> ocRoomInfoArrayList;
	
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
    		Bundle savedInstanceState) 
     {
    	bundle = getArguments();

    	ocRoomInfo= inflater.inflate(R.layout.fragment_room_info, container, false);
    	occupiedRoomTable= (TableLayout) ocRoomInfo.findViewById(R.id.occupiedRoomTable);
    	textView =  (TextView) ocRoomInfo.findViewById(R.id.apartmentTitle);
    	textView.setText((CharSequence) bundle.get("name"));
    	
    	ocRoomInfoArrayList=bundle.getStringArrayList("room_info");
		TableRow tbFisrtRow =new TableRow(getActivity());
		for(int j =0;j<COLUMN;j++)
		{
			TextView view = new TextView (getActivity());
			 view.setText(Global.firstRow[j]);
			 view.setTextSize(24);
			 view.setGravity(Gravity.CENTER);
			  view.setTextColor(Color.parseColor("#000000"));
			   tbFisrtRow.addView(view);
		}
		occupiedRoomTable.addView(tbFisrtRow);
		for(int i=0;i<ocRoomInfoArrayList.size();)
		{
			TableRow tbRow =new TableRow(getActivity());			    		
			for(int j =0;j<COLUMN;j++)
			{
			    TextView view = new TextView (getActivity());
			    ImageView imgView = new ImageView(getActivity());
			    if("0".equals(ocRoomInfoArrayList.get(i)))
			    {
			        	imgView.setImageResource(R.drawable.green);
			        	imgView.setPadding(5, 5, 5, 5);
			        	tbRow.addView(imgView);
			     }
			     else if("1".equals(ocRoomInfoArrayList.get(i)))
			      {
			        	imgView.setImageResource(R.drawable.pink);
			        	imgView.setPadding(5, 5, 5, 5);
			        	tbRow.addView(imgView);
			      }
			       else{
			       view.setText(ocRoomInfoArrayList.get(i));
			        view.setTextSize(24);
			        view.setGravity(Gravity.CENTER);
			        view.setTextColor(Color.parseColor("#000000"));
			        tbRow.addView(view);
			    	}
			   i++;
			 }
			 occupiedRoomTable.addView(tbRow);
		}   	
    	return ocRoomInfo;
    }
}
